//Main.java http://www.orhandemirel.com/blog/kmeans-clustering/
package kmeanstest;
 
import com.orhandemirel.clustering.Kmeans;
import java.util.ArrayList;
 
/**
 *
 * @author Selcuk Orhan DEMIREL
 */
public class Main {
 
      public static void main(String[] args) {
    	  if (args.length != 1) {
    		  System.out.println("ERROR: Number of clusters argument should be inserted");
    		  System.exit(0);
    	  }
    	  int numClusters = Integer.valueOf(args[0]);
    	  
        double[][] data = {{1d,2d},{2d,4d},{1d,1d},{0d,0d},{2d,5d}, {2d,15d}, {4d,20d}, {3d,2d}, {3d,3d}, {5d,10d}, {5d,9d}, {5d,12d}, {6d,15d}, {6d,16d}, {6d,17d}, {6d,0d}, {6d,6d}};
        
        System.out.println("DEMO POINTS:");
        for (double[] point: data) {
        	System.out.println(point[0] + ", " + point[1]);
        }
        System.out.println();
        Kmeans kmeans = new Kmeans(data, numClusters);
        //kmeans.setEpsilon(0.000001);
        kmeans.calculateClusters();
        System.out.println("OUTPUT:");
        System.out.println();
        ArrayList[] clusters = kmeans.getClusters();
        int clusterNumber = 1;
        for(ArrayList cluster: clusters)
        {
            System.out.println("CLUSTER " + clusterNumber);
            for(Object dat:cluster)
            {
                for(int i=0;i<2;i++)
                    System.out.print(((double[])dat)[i] + " ");
                System.out.println();
            }
            clusterNumber++;
            System.out.println();
        }
        /*
        System.out.println("OTHER DATA");
        System.out.println(kmeans.getClusterVars()[0]);
        System.out.println(kmeans.getClusterVars()[1]);
        System.out.println(kmeans.getTotalVar());
        System.out.println(kmeans.getClusterCenters()[0][0] + " " + kmeans.getClusterCenters()[0][1]);
        System.out.println(kmeans.getClusterCenters()[1][0] + " " + kmeans.getClusterCenters()[1][1]);
        */
    }
 
}